home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-18 | 3.1 KB | 92 lines | [TEXT/PJMM] |
- unit HighLevelEvents;
-
- interface
- uses
- AppleEvents, Globals;
-
- procedure DoHighLevelEvent (e: eventRecord);
- procedure DoAppleEvent (e: EventRecord);
-
- implementation
-
- {############################ High Level Events #############################}
-
- { Handle high level events. We handle the following high level events:}
- {- The standard MultiFinder events, suspend and resume.}
- {- The required Apple Events, Open Application, Open Document, Print Document and QuitApplication.}
- {All except Quit Application merely reports that they havn't done anything.}
- {Entire unit added by LIR}
-
-
-
- {Handle the required Apple events:}
- {DoOpenApp,DoOpenDoc,DoPrintDoc,DoQuitApp}
- {MyGotRequiredParams: From MSG demo my Mark Pilgrim, tells whether we have handled all we have to or not.}
- function MyGotRequiredParams (theAppleEvent: AppleEvent): OSErr;
- var
- returnedType: DescType;
- actualSize: Size;
- begin
- if AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard, returnedType, nil, 0, actualSize) = errAEDescNotFound then
- MyGotRequiredParams := noErr
- else
- MyGotRequiredParams := errAEParamMissed;
- end;
- function DoOpenApp (theAppleEvent, reply: AppleEvent; refCon: Longint): OSErr;
- begin
- {What am I supposed to do here?}
- DoOpenApp := MyGotRequiredParams(theAppleEvent);
- end;
- function DoOpenDoc (theAppleEvent, reply: AppleEvent; refCon: Longint): OSErr;
- begin
- DoOpenDoc := errAEEventNotHandled; {We don't open any documents!}
- end;
- function DoPrintDoc (theAppleEvent, reply: AppleEvent; refCon: Longint): OSErr;
- begin
- DoPrintDoc := errAEEventNotHandled; {We don't print any documents!}
- end;
- function DoQuitApp (theAppleEvent, reply: AppleEvent; refCon: Longint): OSErr;
- begin
- userdone := true; {If I'm told to quit, I'll quit.}
- DoQuitApp := MyGotRequiredParams(theAppleEvent);
- end;
-
- {Init Apple events}
- {Perhaps I'm cheating, but I don't call this until I get the first Apple event.}
- {IMHO, that's the simplest way to support them without a lot of boring Gestalt checks.}
- procedure AppleEventInit;
- var
- error: OSerr;
- begin
- if gAppleEventsInitialized then
- exit(AppleEventInit);
- gAppleEventsInitialized := true;
- error := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, @DoOpenApp, 0, false);
- error := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, @DoOpenDoc, 0, false);
- error := AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, @DoPrintDoc, 0, false);
- error := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, @DoQuitApp, 0, false);
- {I ignore errors.}
- end;
-
- {Handle suspend or resume events.}
- {Here, I choose to use suspend/resume events to change gSleep. Increasing gSleep when we are}
- {in the background reduces processing load.}
- procedure DoHighLevelEvent (e: eventRecord);
- begin
- if BAND(BROTL(e.message, 8), $FF) = SuspendResumeMessage then
- if BAnd(e.message, 1) <> 0 then
- gSleep := 5 {Resume event}
- else
- gSleep := 30; {Suspend event}
- end;
-
- {Handle Apple Events}
- procedure DoAppleEvent (e: EventRecord);
- begin
- if not gAppleEventsInitialized then {My little "cheat" into compatibility}
- AppleEventInit;
- if AEProcessAppleEvent(e) <> noErr then
- ;
- end;
-
- end.